package file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class ReadAndWriteFileMain {
	
	public static void main(String[] args) throws IOException {
		
		File f = new File("C:\\java-master\\poster.jpg");
		
		long fileSize = f.length();
		
		System.out.println("파일크기: " + fileSize + " B");
		
		FileInputStream fis = new FileInputStream(f);
		
		// 파일 크기와 동일한 크기의 버퍼 배열 생성
		byte[] b = new byte[(int)fileSize];
		int len = -1;
		while ((len = fis.read(b)) > -1) {
			System.out.println("한 번 읽음");
		}
		
		fis.close();
		
		FileOutputStream fos = new FileOutputStream("C:\\java-master\\poster2.jpg");
		
		fos.write(b);
		
		fos.close();
	}
	
}
